模拟实现strlen
1.计数器

size_t my_strlen(const char* str)
{
	assert(str);
	char* cur = str;
	size_t count=0;
	while (*cur++)
	{
		count++;
	}
	return count;
}
2.递归
size_t my_strlen( const char* str)
{
	assert(str);
	if (*str == '\0')
	{
		return 0;
	}
	else
	{
		return 1 + my_strlen(str + 1);
	}
}
3.指针
size_t my_strlen(const char* str)
{
	assert(str);
	char* end = str;
	while (*end++)
	{
		;
	}
	return end - str-1;
}
int main()
{
	char str[] = "abcdef";
	printf("%d\n", my_strlen(str));
	return 0;
}




模拟实现strcpy
char* my_strcpy(char* des, const char* sour)
{
	assert(des && sour);
	char* cur = des;
	while (*cur++ = *sour++)
	{
		;
	}
	return des;
}
int main()
{
	char sour[] = "abcdef";
	char des[20] = { 0 };
	printf("%s\n", my_strcpy(des, sour));
	return 0;
}




//模拟实现strcmp
int my_strcmp(const char* str1, const char* str2)
{
	assert(str1 && str2);
	char* s1 = str1;
	char* s2 = str2;
	while (*s1 == *s2)
	{
		s1++;
		s2++;
		if (*s1 == '\0')
		{
			return 0;
		}
	}
	return *s1 - *s2;
}

int main()
{
	char str1[] = "abbcde";
	char str2[] = "abbcde";
	printf("%d", my_strcmp(str1, str2));
	return 0;
}



模拟实现strcat

char* my_strcat(char* des, const char* sour)
{
	assert(des && sour);
	char* head = des; //保存头指针
	while (*des++)
	{
		;
	}
	des--;
	while (*des++ = *sour++)
	{
		;
	}
	return head;
}

int main()
{
	char arr1[] = "abcdef\0xxxx";
	char arr2[] = "hijk";
	printf("%s\n", my_strcat(arr1, arr2));
	return 0;
}